package net.xdclass;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.DateType;

/**
 * 小滴课堂,愿景：让技术不再难学
 *
 * @Description
 * @Author 二当家小D
 * @Remark 有问题直接联系我，源码-笔记-技术交流群
 * @Version 1.0
 **/
public class MyBatisPlusGenerator {

    public static void execute(){
        //配置数据库参数
        DataSourceConfig.Builder config = new DataSourceConfig.Builder(
                "jdbc:mysql://49.234.21.142:3306/dcloud-aipan?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true",
                "root",
                "123456");
        String [] tables = {"account","file","account_file","file_chunk","file_suffix","file_type","share","share_file","storage"};
        //mybatisPlus总共支持6种配置
        FastAutoGenerator.create(config)
                //全局配置
                .globalConfig((scanner,builder)  -> {
                    //配置作者
                    builder.author("tom")
                            .enableSpringdoc()
                            .disableOpenDir()
                            .dateType(DateType.ONLY_DATE)
                            //配置时间
                            .commentDate("yyyy-MM-dd")
                            //输出目录
                            .outputDir("/Users/tom/Desktop/dcloud-aipan/rose");
                })
                //包配置
                .packageConfig((scanner,builder) -> {
                    //配置父包名
                    builder.parent("net.xdclass");
                    builder.entity("model");
                    builder.mapper("mapper");
                })
                //策略配置
                .strategyConfig((scanner,builder)  -> {
                    // 设置需要生成的表名
                    builder.addInclude(tables)
                            //配置模型
                            .entityBuilder().enableFileOverride()
                            .idType(IdType.ASSIGN_ID)
                            .enableLombok()
                            .logicDeleteColumnName("del")
                            .enableTableFieldAnnotation()
                            .formatFileName("%sDO")
                            .controllerBuilder().disable()
                            .serviceBuilder().disable()
                            .mapperBuilder()
                            .enableFileOverride()
                            .formatMapperFileName("%sMapper")
                            .superClass(BaseMapper.class)
                            .enableBaseResultMap()
                            .enableBaseColumnList()
                            .formatXmlFileName("%sMapper");
                })
                //模板配置
                .templateConfig((scanner,builder)->{
                    //配置不需要生成的文件
                  builder.disable(TemplateType.CONTROLLER,TemplateType.SERVICE,TemplateType.SERVICE_IMPL);
                })
                //注入配置
//                .injectionConfig((scanner,builder)  ->{})
                //模板引擎配置
//                .templateConfig(builder->{})
                .execute();
    }

    public static void main(String[] args) {
        MyBatisPlusGenerator.execute();
    }
}